package grid.celebritysocial.adapter;

import grid.celebritysocial.R;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class InfoListAdapter extends ArrayAdapter<InfoListItem>{

	private LayoutInflater inflater;
	private List<InfoListItem> items;
	private int textViewResourceId;


	public InfoListAdapter(Context context, int textViewResourceId, List<InfoListItem> items){
		super(context, textViewResourceId,items);

		// リソースIDと表示アイテムを保持
		this.textViewResourceId = textViewResourceId;
        this.items = items;

        // ContextからLayoutInflaterを取得
		inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	/**
	 * 1アイテム分のビューを取得.
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		View view  = convertView;

		//nullの場合(最初の呼び出し)
		if(view == null){
			view = inflater.inflate(textViewResourceId, null);
		}

		// 対象のアイテムを取得
		InfoListItem item = items.get(position);

		TextView date = (TextView)view.findViewById(R.id.info_date);
		date.setText(item.getInfo_date());

		TextView textView = (TextView)view.findViewById(R.id.info_text);
		textView.setText(item.getInfo_text());
		Log.d("MyApp",item.getInfo_text() );

		return view;
	}

}